/**
 * 客户端api
 */

import http from '@/common/http'

const api = {}

/**
 * @typedef {object} miniLoginData
 * @property {string} openid
 * @property {string} session_key
 * @property {string} token
 */
/**
 * @typedef {object} miniLoginResponse
 * @property {number} code - 返回的状态码
 * @property {string} msg - 返回的消息
 * @property {miniLoginData} data
 */
/**
 * 授权登录
 * @param {object} data
 * @param {string} data.code - 授权码
 * @returns {miniLoginResponse}
 */
api.postMiniLogin = (data, config = {}) => http.post('/mini/login', data, config)
/** 获取用户信息 */
api.postUserInfo = (data, config = {}) => http.post('/mini/users/info', data, config)
/**
 * 修改用户信息
 * @param {object} data
 * @param {string} data.openid      - 小程序唯一编号
 * @param {string?} data.nickName    - 昵称
 * @param {string?} data.userName    - 姓名
 * @param {string?} data.phone       - 手机
 * @param {string?} data.headImgUrl  - 头像url
 */
api.postUserEdit = (data, config = {}) => http.post('/mini/users/edit', data, config)
//手机号绑定
api.postBindPhone = (data, config = {}) => http.post('/mini/users/bind/phone', data, config)

api.postUpdateCount = (data, config = {}) => http.post('/batch/update/count', data, config)

api.postUpdateStatus = (data, config = {}) => http.post('/batch/update/status', data, config)



/** 商品列表 */
api.postProductList = (data, config = {}) => http.post('/mini/product/list', data, config)
/**
 * 商品详情
 * @param {object} data
 * @param {number} data.id - 商品id
 */
api.postProductInfo = (data, config = {}) => http.post('/mini/product/info', data, config)

/**
 * 订单列表
 * @param {object} data
 * @param {number} data.status - 状态，查看字典 self_orders_status
 */
api.postOrderList = (data, config = {}) => http.post('/mini/orders/list', data, config)
/**
 * 订单详情
 * @param {object} data
 * @param {number} data.id - 主键ID
 */
api.postOrderInfo = (data, config = {}) => http.post('/mini/orders/info', data, config)
/**
 * 发送短信
 * @param {object} data
 * @param {string} data.customerPhone - 手机号
 */
// api.sendSms = (data, config = {}) => http.post('/mini/orders/send/sms', data, config)
api.sendSms = (data, config = {}) => http.post('/mini/sms/send/sms', data, config)

api.CheckSms = (data, config = {}) => http.post('/mini/sms/check/sms', data, config)

// {customerPhone, code}
/**
 * 查询手机号下的订单列表
 * @param {object} data
 * @param {string} data.customerPhone  - 手机号
 * @param {string} data.code           - 短信验证码
 */
api.postOrderSearchPhone = (data, config = {}) => http.post('/mini/orders/search/phone', data, config)
/**
 * 查询订单号
 * @param {object} data
 * @param {string} data.orderNumber - 订单编号
 */
api.postOrderSearchNumber = (data, config = {}) => http.post('/mini/orders/search/number', data, config)

api.postOrderSearchAmount = (data, config = {}) => http.post('/mini/users/customer/amount', data, config)

api.postRecordList = (data, config = {}) => http.post('/mini/pay/record/list', data, config)

export default api
